package cn.edu.scau.cmi.lixiaoyuan.multition;

import java.util.ArrayList;
import java.util.List;

public class Marshal {
   private static List<Marshal> list = new ArrayList<Marshal>();
   private static Marshal instance;
   public static int marshal_num = 10;
   
   private String name;
   public String getname() {
	   return name;
   }
   private Marshal(String name) {
 	  this.name = name ;
   }
   public static Marshal getInstance(String name) {
	   int judgement = 0;//判断是否有相同名字
	   int i=0;
       if(marshal_num==0) {
		   return null;
	   }
	   for(i=0;i<list.size();i++) {
		   if(list.get(i).getname().equals(name)) {
			   instance =  list.get(i);
			   judgement=1;
			   break;
		   }
	   }
	   if(judgement==0) {
		   instance = new Marshal(name);
		   list.add(instance);
		   marshal_num--;
		   return instance;
	   }
	  return instance;
 	  
   }
   
   public static String getString(String name) {
	   boolean judgement = true;//判断是否有相同名字
	   
	   int i=0;
       if(marshal_num==0) {
		   return "10个用例已经用完";
	   }
	   for(i=0;i<list.size();i++) {
		   if(list.get(i).getname().equals(name)) {
			   System.out.println(list.get(i).getname());
			   System.out.println(name);
			   judgement= false;
			   break;
		   }
		   
	   }
	  
	   if(judgement) {
		   instance = new Marshal(name);
		   list.add(instance);
		   marshal_num--;
		   return instance.getname()+":"+instance;
		   
	   }
	  
	   return "名字重複，用例已經創建";
 	  
	   
	  
   }
}
